package org.openems;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.openems.meta.ParameterModelMeta;
import org.openems.model.ParameterModel;
import org.slim3.datastore.Datastore;

@Path("/parameterKey")
public class ParameterKeyResource {
    @GET
    @Produces(MediaType.APPLICATION_XML)
    public StringListEntities get(@QueryParam("type") String type) {
        ParameterModelMeta e = ParameterModelMeta.get();

        StringListEntities ret = new StringListEntities();
        List<ParameterModel> models = Datastore.query(e).filter(e.entityKey.equal(type)).asList();
        for (ParameterModel model : models) {
            if (type != null) {
                ret.list.add(model.getEntityKey());
            }
            else {
                if (model.getEntityKey().equals(type)) {
                    ret.list.add(model.getEntityKey());
                }
            }
        }
        return ret;
    }
}
